var express = require('express')
var router = express.Router();
var mongoose = require('mongoose')
var Goods = require('../models/goodsList')

//连接MongoDB数据库
mongoose.connect('mongodb://127.0.0.1:27017/db_umbrella');

mongoose.connection.on("connected",function(){
    console.log("连接成功");
});
mongoose.connection.on("error",function(){
    console.log("连接失败");
});
mongoose.connection.on("disconnected",function(){
    console.log("连接断开");
});
router.get("/",function(req,res,next){
    Goods.find({},function(err,doc){
        if(err){
            res.json({
                status:'1',
                msg:err.message
            });
        }else{
            res.json({
                status:'0',
                msg:'',
                result:{
                    conut:doc.length,
                    list:doc
                }
            })
        }
    })
})  

router.get("/detail",function(req,res,next){
    Goods.find("'umbreId':'10002'",function(err,doc){
        if(err){
            res.json({
                status:'1',
                msg:err.message
            });
        }else{
            res.json({
                status:'0',
                msg:'',
                result:{
                    conut:doc.length,
                    list:doc
                }
            })
        }
    })
})  
module.exports = router;